<? $errMsg =''?>
<?
switch ($_GET['action']){
	case 'del' :
		$id = $_GET['id'];
		$sql = "delete from tbl_order_detail where id='".$id."'";
		$result = mysql_query($sql,$conn);
		echo mysql_error();
		if ($result) $errMsg = "&#272;ã xóa thành công.";
			else $errMsg = "Không th&#7875; xóa d&#7919; li&#7879;u !";
		break;
}

if (isset($_POST['btnDel'])){
	$cnt=0;
	if($_POST['chk']!=''){
		foreach ($_POST['chk'] as $id){
			@$result = mysql_query("delete from tbl_order_detail where id='".$id."'",$conn);
			if ($result) $cnt++;
		}
		$errMsg = "&#272;ã xóa ".$cnt." phần tử.";
	}else{
		$errMsg = 'Hãy chọn trước khi xóa !';
	}
}
?>
<form method="POST" name="frmForm" action="./">
<input type="hidden" name="act" value="order_detail">
<input type="hidden" name="id" value="<?=$_REQUEST['id']; ?>">
<?
$orderId=$_REQUEST['id'];
if ($orderId=='') return;
$orderinfo=getRecord("tbl_order","id=".$orderId);
$cust=getRecord("tbl_member","id=".$orderinfo['member_id']);
?>



<table border="1" cellpadding="2" bordercolor="#C9C9C9" width="100%">
	<tr>
		<th width="20" class="title"><input type="checkbox" name="chkall" onclick="chkallClick(this);"></th>
		<th class="title" nowrap colspan="2"><a class="title" href="<?=getLinkSort(2)?>">Chức năng</a></th>		
		<th width="124" class="title">Mã hàng</th>
		<th width="255" class="title">Tên hàng</th>
		<th width="137" class="title">S&#7889; l&#432;&#7907;ng</th>
		<th width="122" class="title">&#272;&#417;n giá</th>
		<th width="168" class="title">Thành ti&#7873;n</th>    
	</tr>
  
<?
$page = $_GET["page"];
$sql="select * from tbl_order_detail where order_id=$orderId order by id";
$result=mysql_query($sql,$conn);
$i=0;
$tong=0;
while($row=mysql_fetch_array($result)){
	$pro=getRecord("tbl_product","id=".$row['product_id']);
	$color = $i++%2 ? '#d5d5d5' : '#e5e5e5';
?>
  
	<tr>
		<td bgcolor="<?=$color; ?>" class="smallfont">
			<input type="checkbox" name="chk[]" value="<?=$row['id']; ?>"></td>
		<td width="32" bgcolor="<?=$color; ?>" class="smallfont">
			<a href="./?act=product_m&id=<?=$pro['id']; ?>&page=<?=$page?>">Sửa</a>		</td>
		<td width="32" bgcolor="<?=$color; ?>" class="smallfont">
			<a onclick="return confirm('B&#7841;n có ch&#7855;c ch&#7855;n mu&#7889;n xoá ?');" href="./?act=order_detail&action=del&id=<?=$row['id']; ?>">Xóa</a>		</td>
		<td bgcolor="<?=$color; ?>" class="smallfont" align="center"><?=$pro['id']; ?></td>
		<td bgcolor="<?=$color; ?>" class="smallfont"><?=$pro['name']; ?></td>
		<td bgcolor="<?=$color; ?>" class="smallfont" align="center"><?=$row['quantity']; ?></td>
		<td bgcolor="<?=$color; ?>" class="smallfont" align="right"><?=number_format($row['price']); ?></td>
		<td bgcolor="<?=$color; ?>" class="smallfont" align="right"><?=number_format($row['quantity']*$row['price']); ?>
		<? 
		$tien=$row['quantity']*$row['price'];
		$tong=$tong+$tien;
		?>
		</td>
	</tr>
<?
}
?>
</table>
<table width="100%">
	<tr>
		<td width="30%">
<input type="submit" value="Xóa chọn" name="btnDel" onclick="return confirm('B&#7841;n có ch&#7855;c ch&#7855;n mu&#7889;n xoá ?');" class="button">
<td align="right"><font color="#FF0000" size="1"><b>Tổng số tiền : <?=number_format($tong)?>&nbsp;<?=$currencyUnit?></b></font></td>
</td></tr></table>
</form>
<table align="center" border="0" cellpadding="2" cellspacing="2" width="90%">
<tbody><tr>
    <td colspan="2" class="smallfont"><font color="#B11400"><strong>Thông tin thanh toán: </strong></font></td>
  </tr>
  <tr>
    <td width="25%" class="smallfont">Họ tên:</td>
    <td class="smallfont"><?=$cust["name"]?></td>

  </tr>
    <tr>
    <td class="smallfont">Email:</td>
    <td class="smallfont"><?=$cust["email"]?></td>
  </tr>
  <tr>
    <td class="smallfont">Địa chỉ:</td>

    <td class="smallfont"><?=$cust["address"]?></td>
  </tr>
    <tr>
    <td class="smallfont">Thành phố:</td>
    <td class="smallfont"><?=$cust["city"]?></td>
  </tr>
  <tr>
    <td class="smallfont">Quốc gia:</td>

    <td class="smallfont"><?=$cust["country"]?></td>

  </tr>

  <tr>
    <td class="smallfont">Điện thoại:</td>
    <td class="smallfont"><?=$cust["tel"]?></td>
  </tr>
</tbody></table>
<br>
<table align="center" border="0" cellpadding="2" cellspacing="2" width="90%">

  <tbody>
  <tr>
    <td colspan="2" class="smallfont"><font color="#B11400"><strong>Thông tin giao hàng: </strong></font></td>
  </tr>
  <tr>

    <td width="25%" class="smallfont">Họ tên:</td>
    <td class="smallfont"><?=$cust["company"]?></td>
  </tr>
  <tr>
    <td class="smallfont">Địa chỉ:</td>
    <td class="smallfont"><?=$cust["fax"]?></td>
  </tr>

  <tr>
    <td class="smallfont">Thành phố:</td>
    <td class="smallfont"><?=$cust["website"]?></td>
  </tr>
  <tr>
    <td class="smallfont">Quốc gia:</td>

    <td class="smallfont"><?=$cust["uid"]?></td>

  </tr>
  <tr>
    <td class="smallfont">Điện thoại:</td>
    <td class="smallfont"><?=$cust["pwd"]?></td>
  </tr>

			
</tbody></table>
<br>
<table align="center" border="0" cellpadding="2" cellspacing="2" width="90%">
<hr size="1" color="#CCCCCC" />
  <tbody><tr>
    <td colspan="2" align="center" class="smallfont"><font color="#B11400">Yêu cầu về thời gian giao hàng và chi tiết khác </font></td>
  </tr>
  <tr>

    <td colspan="2" align="center" class="smallfont"><?=$cust["note"]?></td>
  </tr>
</tbody></table>
<script language="JavaScript">
function chkallClick(o) {
  	var form = document.frmForm;
	for (var i = 0; i < form.elements.length; i++) {
		if (form.elements[i].type == "checkbox" && form.elements[i].name!="chkall") {
			form.elements[i].checked = document.frmForm.chkall.checked;
		}
	}
}
</script>
<? if($errMsg!=''){echo '<p align=center class="err">'.$errMsg.'<br></p>';}?>